package com.liyl.controller;

import com.liyl.service.DaleTouService;
import com.liyl.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通用工具API接口
 *
 * @author liyl
 */
@Slf4j
@Api(value = "公用接口", tags = {"公用接口"})
@RestController
public class CommonController {

    @Autowired
    private DaleTouService daleTouService;

    @ApiOperation("根据key获取val")
    @ApiOperationSort(1)
    @GetMapping(value = "/valueWithKey", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Result valueWithKey(@ApiParam(value = "redis的key", required = true) @RequestParam String key) {
        String msg = daleTouService.getValFromRedis(key);
        return Result.success(msg);
    }
    @ApiOperation("根据key设置val")
    @ApiOperationSort(2)
    @GetMapping(value = "/setValueWithKey", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Result setValueWithKey(@ApiParam(value = "redis的key", required = true) @RequestParam String key,
                                  @ApiParam(value = "redis的val", required = true) @RequestParam String val) {
        daleTouService.setValFromRedis(key, val);
        return Result.ok();
    }


}